#pragma once            

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<ctime>    


#define COLOR_NONE "\033[0;m"
#define BLUE "\033[0;34m"
#define YELLOW "\033[0;33m"
#define RED "\033[0;31m"
#define LIGHT_RED_INV "\033[5;7;31m"

#define DEBUG 1    
#define INFO 2    
#define WARNING 3    
#define ERROR 4    
#define FATAL 5    



#define logger_debug(level,fmt,file_name,line) printf(BLUE),printf("[%s]",#level);   
#define logger_info(level,fmt,file_name,line) printf(COLOR_NONE),printf("[%s]",#level);     
#define logger_warning(level,fmt,file_name,line) printf(YELLOW),printf("[%s]",#level);
#define logger_error(level,fmt,file_name,line) printf(RED),printf("[%s]",#level);
#define logger_fatal(level,fmt,file_name,line) printf(LIGHT_RED_INV),printf("[%s]",#level);


#define LOG(level,message) log(level,message,__FILE__,__LINE__)


class Log {
public:
    static void log(const int level, const std::string& message, const std::string& file_name, int line)
    {
        //获取当前时间
        std::time_t now = std::time(nullptr);
        //转化为本地时间
        std::tm* local = std::localtime(&now);
        //格式化时间
        char buffer[64];
        std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %X", local);

        switch (level) {
        case DEBUG:
#ifdef USE_DEBUG
            logger_debug(DEBUG, message, file_name, line);
            printf(COLOR_NONE);
        std::cout << "[" << buffer << "]" << message << " [>> " << file_name << "][" << line << "]" << "[" << now << "]" << std::endl;
#endif
            break;
        case INFO:
            logger_info(INFO, message, file_name, line);
            printf(COLOR_NONE);
        std::cout << "[" << buffer << "]" << message << " [>> " << file_name << "][" << line << "]" << "[" << now << "]" << std::endl;
            break;
        case WARNING:
            logger_warning(WARNING, message, file_name, line);
            printf(COLOR_NONE);
        std::cout << "[" << buffer << "]" << message << " [>> " << file_name << "][" << line << "]" << "[" << now << "]" << std::endl;
            break;
        case ERROR:
            logger_error(ERROR, message, file_name, line);
            printf(COLOR_NONE);
        std::cout << "[" << buffer << "]" << message << " [>> " << file_name << "][" << line << "]" << "[" << now << "]" << std::endl;
            break;
        case FATAL:
            logger_fatal(FATAL, message, file_name, line);
            printf(COLOR_NONE);
        std::cout << "[" << buffer << "]" << message << " [>> " << file_name << "][" << line << "]" << "[" << now << "]" << std::endl;
            break;
        }

    }
};
